#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>

int maxLengString(std::string s)
{
    std::unordered_set<char> temp;
    int n = s.size();
    int right = 0;
    int Max = 0;
    for(int i = 0;i < n;++i)
    {
        while(right < n && !temp.count(s[right]))
        {
            temp.insert(s[right]);
            right++;
        } 
        Max = std::max(Max,right - i);
        if(right == n)
        {
            return Max;
        }
        temp.erase(s[i]);
    }
    return Max;
}

void test()
{
    std::string s = "abcdabcabcdergabc";
    int ret = maxLengString(s);
    std::cout << "s:" << s  << " 子串最长无重复为" << ret << std::endl;
}
int main()
{
    test();
    return 0;
}